package test20230417;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/4/17 23:48
 */
public class Main02 {
    public static void main(String[] args) {
        // 创建 Number 实例调用相应的方法, 显示加减乘除的结果
        Number number = new Number(77, 7);
        System.out.println("77 + 7 = " + number.addition());
        System.out.println("77 - 7 = " + number.subtraction());
        System.out.println("77 * 7 = " + number.multiplication());
        System.out.println("77 ÷ 7 = " + number.division());
    }
}

// 计算器类
class Number {
    private int n1;
    private int n2;

    public Number(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }

    // 加法
    public int addition() {
        return n1 + n2;
    }

    // 减法
    public int subtraction() {
        return n1 - n2;
    }

    // 乘法
    public int multiplication() {
        return n1 * n2;
    }

    // 除法
    // 使用 double 防止数据精度损失
    public double division() {
        return (double) n1 / (double) n2;
    }
}
